﻿// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using Abp.Json;
using GCT.Foundation.PageFilters;
using Microsoft.EntityFrameworkCore;

namespace GCT.Foundation.EntityFrameworkCore
{
    public static class FoundationTemplateDbContextExtensions
    {
        /// <summary>
        /// 配置 FoundationTemplate 模块
        /// </summary>
        /// <param name="modelBuilder"></param>
        /// <returns></returns>
        public static ModelBuilder ConfigureFoundationTemplate(this ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<PageFilterElement>(builder =>
            {
                builder.Property(u => u.Args)
                    .HasConversion(
                        u => u.ToJsonString(false, false),
                        u => u.FromJsonString<Dictionary<string, object>>());
                builder.Property(u => u.ValueChange)
                    .HasConversion(u => u.ToJsonString(false, false),
                        u => u.FromJsonString<List<string>>());
            });

            return modelBuilder;
        }
    }
}
